import {Component, OnInit} from '@angular/core';
import {_HttpClient} from '@delon/theme';
import {Banner} from '../banner';
import {BannerService} from '../banner.service';
import {NzMessageService} from 'ng-zorro-antd';

@Component({
    selector: 'app-list',
    templateUrl: './list.component.html',
})
export class ListComponent implements OnInit {

    data: Banner[] = [];
    total = 0;
    pagesize = 10;
    pageCurrent = 1;

    constructor(
        private bannerService: BannerService,
        private msgService: NzMessageService,
    ) {
    }

    ngOnInit() {
        this.getlist(this.pageCurrent);
    }

    getlist($event) {
        this.bannerService.getBannerList($event - 1).subscribe(res => {
            this.data = res['list'];
            this.total = res['totalElement'];
            this.pagesize = res['pageSize'];
            this.pageCurrent = $event;
        }, __ => {
        });
    }

    delVide(item) {
        const index = this.data.indexOf(item);
        this.data = [...this.data.slice(0, index), ...this.data.slice(index + 1, this.data.length)];
        this.bannerService.delBanner(item['id']).subscribe(res => {
            this.msgService.success('删除成功');
            this.getlist(this.pageCurrent);
        }, __ => {
        });
    }
}
